package www.shw.com.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import www.shw.com.bean.LvEx;
import www.shw.com.bean.Us;
import www.shw.com.mapper.LvMapper;
import www.shw.com.service.LvService;
@Service
public class LvServiceImpl implements LvService{

	@Resource
	private LvMapper lvMapper;

	@Override
	public Integer selectCount(String name) {
		return lvMapper.selectCount(name);
	}
	@Override
	public List<LvEx> selectObjects(Integer startIndex, Integer rows, String name) {
		return lvMapper.selectObjects(startIndex,rows,name);
	}
	@Override
	public LvEx selectById(LvEx lv) {
		return lvMapper.selectById(lv);
	}
	@Override
	public List<Us> selectUs() {
		return lvMapper.selectUs();
	}
	/*@Resource
	private RabbitTemplate rabbitTemplate;
	private ObjectMapper objectMapper = new ObjectMapper();*/
	@Override
	public void insert(LvEx lv) {
		lvMapper.insertObject(lv);
		lvMapper.insertMiddle(lv);
		/*try {
			String json = objectMapper.writeValueAsString(lv);
			rabbitTemplate.convertAndSend("myqueue",json);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}*/
	}

	@Override
	public void delete(Integer[] ids) {
		lvMapper.deleteMiddle(ids);
		lvMapper.deleteObjects(ids);

	}
	@Override
	public void update(LvEx lv) {
		lvMapper.deleteMiddle(new Integer[]  {lv.getCid()});
		lvMapper.update(lv);
		lvMapper.insertMiddle(lv);
	}
}
